package cn.qicaiwang.open.app.server.Impl;

import cn.qicaiwang.open.app.entity.MembershipPlan;
import cn.qicaiwang.open.app.mapper.MembershipPlanMapper;
import cn.qicaiwang.open.app.server.MembershipPlanService;
import cn.qicaiwang.open.common.exception.BusinessException;
import com.baomidou.mybatisplus.core.conditions.Wrapper;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.squareup.okhttp.internal.framed.ErrorCode;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.Collection;
import java.util.List;
import java.util.Map;
import java.util.function.Function;

/**
 * 会员套餐服务实现类
 */
@Service
public class MembershipPlanServiceImpl implements MembershipPlanService {

    @Autowired
    private MembershipPlanMapper membershipPlanMapper;

    @Override
    public MembershipPlan createPlan(MembershipPlan plan) {
        membershipPlanMapper.insert(plan);
        return plan;
    }

    @Override
    public MembershipPlan updatePlan(MembershipPlan plan) {
        // 检查套餐是否存在
        MembershipPlan existingPlan = membershipPlanMapper.selectById(plan.getId());
        if (existingPlan == null) {
            throw new BusinessException("Plan not found with id: " + plan.getId());
        }

        membershipPlanMapper.update(plan);
        return plan;
    }



    @Override
    public MembershipPlan getPlanById(Long id) {
        MembershipPlan plan = membershipPlanMapper.selectById(id);
        if (plan == null) {
            throw new BusinessException("Plan not found with id: " + id);
        }
        return plan;
    }

    @Override
    public List<MembershipPlan> getAllPlans() {
        return membershipPlanMapper.selectAll();
    }

    @Override
    public List<MembershipPlan> getActivePlans() {
        return membershipPlanMapper.selectActivePlans();
    }

    @Override
    public boolean saveBatch(Collection<MembershipPlan> entityList, int batchSize) {
        return false;
    }

    @Override
    public boolean saveOrUpdateBatch(Collection<MembershipPlan> entityList, int batchSize) {
        return false;
    }

    @Override
    public boolean updateBatchById(Collection<MembershipPlan> entityList, int batchSize) {
        return false;
    }

    @Override
    public boolean saveOrUpdate(MembershipPlan entity) {
        return false;
    }

    @Override
    public MembershipPlan getOne(Wrapper<MembershipPlan> queryWrapper, boolean throwEx) {
        return null;
    }

    @Override
    public Map<String, Object> getMap(Wrapper<MembershipPlan> queryWrapper) {
        return null;
    }

    @Override
    public <V> V getObj(Wrapper<MembershipPlan> queryWrapper, Function<? super Object, V> mapper) {
        return null;
    }

    @Override
    public BaseMapper<MembershipPlan> getBaseMapper() {
        return null;
    }

    @Override
    public Class<MembershipPlan> getEntityClass() {
        return null;
    }
}